package pe.com.mowa.siscobsms.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pe.com.mowa.siscobsms.bean.analista;
import pe.com.mowa.siscobsms.bean.persona;
import pe.com.mowa.siscobsms.bean.proyecto;
import pe.com.mowa.siscobsms.datos.conProyecto;


/**
 * Servlet implementation class setPrestamo
 */
public class setPrestamo extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public setPrestamo() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
 	    PrintWriter out = response.getWriter();
	    
 	    String idpersona = request.getParameter("idpersona");
 	    String idlocal = request.getParameter("idlocal");
 	    String mnentre = request.getParameter("mnentre");
 	    String cuotas = request.getParameter("cuotas");
 	    String comentario = request.getParameter("comentario");
 	    float interes = Float.parseFloat(request.getParameter("interes"));
	    
	    
 	    out.println("<script>");
	    out.println("alert('registro correcto'); window.parent.close();");
	    out.println("</script>");
	    
	    conProyecto cp = new conProyecto();
	    
	    proyecto pres = new proyecto();

	    persona per = new persona();
	    per.setId(Integer.valueOf(idpersona));

	    analista loc = new analista();
	    loc.setId(Integer.parseInt(idlocal));
	    pres.setPerson(per);
	    pres.setLocal(loc);
	    pres.setMnentregado(Integer.parseInt(mnentre));   
	    pres.setCuotas(Integer.parseInt(cuotas));
	    pres.setComentario(comentario);
	    pres.setInteres(interes);
	    
	   
	    
	    try {
			cp.setPrestamo(pres);
		//	response.sendRedirect("AdminPrestamos.jsp?idpersona="+idpersona);
		} catch (ClassNotFoundException e) {  
			// TODO Auto-generated catch block 
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	    out.close();

		
		
	}

}
